home *** CD-ROM | disk | FTP | other *** search
- unit Test1;
- { PC Plus sample program. }
- { illustrates two ways of loading a text file: }
- { 1) using standard Pascal procedures and Readln }
- { 2) using built-in Delphi methods and LoadFromFile }
- { }
- { LoadFromFile is simpler to use and faster to load }
- { Readln (or Read), however, gives the programmer more control }
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- TForm1 = class(TForm)
- Memo1: TMemo;
- Button1: TButton;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Button1Click(Sender: TObject);
- { Traditional Pascal text file reading }
- var
- InputFile : TextFile;
- Line : string;
- begin
- Memo1.Lines.Clear;
- if not FileExists( 'Test1.pas' ) then { Check that input file exists }
- ShowMessage('File: Test1.pas not found!')
- else
- begin
- AssignFile(InputFile, 'Test1.pas');
- Reset(InputFile);
- while not Eof(InputFile) do
- begin
- Readln(InputFile, Line);
- Memo1.Lines.Add(Line);
- end;
- CloseFile(InputFile);
- end
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- { Delphi's LoadFromFile file reading method }
- begin
- Memo1.Lines.Clear;
- if not FileExists( 'Test1.pas' ) then { Check that input file exists }
- ShowMessage('File: Test1.pas not found!')
- else
- Memo1.Lines.LoadFromFile('Test1.pas');
- end;
-
- end.
-